package com.ywt.act;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.ywt.main.R;
import com.ywt.tools.Action;
public class RegisterActivity extends Activity {
private Button add_register;
private Button back_register;
//private TextView register_num;
private EditText register_name;
private EditText register_password_confirm;
private EditText register_password;
private EditText register_phonenum;
//private EditText register_popname;
Action action;
 
private Context cxt;   
private String result;
public static String message = "";
public static boolean isRegister = false;
//private DataTools dTools;
Handler handler = new Handler() {
	@Override
	public void handleMessage(Message msg) {
		switch (msg.what) {
		case 0:
//			isRegister = true;
//			action.stopProgressDialog();
//			action.showLongToast(message);
//			Intent aintent = new Intent(RegisterActivity.this, LoginActivity.class);			 
//			setResult(RESULT_OK, aintent);  		 
			RegisterActivity.this.finish();
			break;
		case 1:
//			isRegister = false;
//			action.stopProgressDialog();
//			if(message.equals("")){
				action.showShortToast("异常，开发中！");
//			}else{
//			action.showShortToast(message);
//			}
			break;	
		default:
			super.handleMessage(msg);
		}
	}
};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_register);
		 cxt=RegisterActivity.this;
//		 dTools = new DataTools();
		action=new Action(this);
		add_register=(Button)findViewById(R.id.login_register);
		back_register=(Button)findViewById(R.id.register_back);
//		register_num=(TextView)findViewById(R.id.register_num);
		register_name=(EditText)findViewById(R.id.register_name);
		register_password_confirm=(EditText)findViewById(R.id.register_password_confirm);
		register_password=(EditText)findViewById(R.id.register_password);
		register_phonenum=(EditText)findViewById(R.id.register_phonenum);
//		register_popname=(EditText)findViewById(R.id.register_popname);
		back_register.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				RegisterActivity.this.finish();
			}
		});
		
		add_register.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if(register_name.getText().toString().trim().equals("")||register_password.getText().toString().trim().equals("")||register_password_confirm.getText().toString().trim().equals("")||register_phonenum.getText().toString().trim().equals("")){
					action.showLongToast("信息填写不完整！");
				} 
				else{
				action.startProgressDialog(RegisterActivity.this);
				
				
				// 注册界面 只有用户名、 密码、手机号需要提交组织为json
				String userName = register_name.getText().toString().trim();
				String password = register_password.getText().toString().trim();
				String telNum = register_phonenum.getText().toString().trim();
				StringBuffer sb = new StringBuffer();
				sb.append("{" + "\"Login_Name\":\"" + userName 
						+ "\",\"Login_Password\":\"" + password
						+ "\",\"Telephone_Mobile\":\"" + telNum + "\",");
				

				String str = "\"Password_Question\":\"1+1=?\","
						+ "\"Password_Answer\":\"2\"," + "\"Area_Code\":\"11\","
						+ "\"Regsiter_Type\":\"2\"," + "\"Regster_Source\":\"1\","
						+ "\"Regster_IP\":\"192.168.1.1\","
						+ "\"Register_Date\":\"#\"," + "\"DeadLine_Date\":\"\","
						+ "\"User_Status\":\"3\"," + "\"User_Type\":\"2\","
						+ "\"User_Name\":\"  \"," + "\"User_Sex\":\"1\","
						+ "\"User_Post\":\"      \","					 
						+ " \"Telephone_Fixed\":\"00000000000\","
						+ "\"User_Email\":\"xxx@qq.com\","
						+ "\"User_QQ\":\"000000\","
						+ " \"User_Hobbies\":\"  \","
						+ "\"User_Fax\":\"00000000\"," + "\"User_Picture\":\"#\","
						+ "\"User_Address\":\"#\"," + "\"User_Memo\":\"#\","
						+ "\"Company_Name\":\"       \", "
						+ "\"Company_Web\":\"www.baidu.com\", "
						+ "\"Credit_Level\":\"#\"," + "\"Total_Login\":\"#\","
						+ "\"Total_Publish\":\"#\"," + "\"Total_Amount\":\"#\","
						+ "\"Operator_ID\":\"#\"";
				sb.append(str);
				
				sb.append("}");
				
				addDev(); 
				}
				
			}
		});
//		register_num.setText("设备号码:"+Util.getDeviceId(RegisterActivity.this)); 
	 
	}
	protected void addDev() {
		new Thread() {
			@Override
			public void run() {
				Message msg = new Message();
				msg.what = 1;
				handler.sendMessageDelayed(msg, 2000);
			
			
			}
		}.start();
	}
}
